package com.zhuanzhuan.hero.user.service.impl;

import com.zhuanzhuan.hero.user.entity.HeroUserVisitRecordStatistic;
import com.zhuanzhuan.hero.user.mapper.HeroUserVisitRecordStatisticMapper;
import com.zhuanzhuan.hero.user.service.IBuryingPointService;
import com.zhuanzhuan.hero.user.util.AsyncUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @ClassName BuryingPointServiceImpl
 * @Description
 * @Author hanjunjun
 * @Date 2024/7/30 14:15
 */
@Slf4j
@Service
public class BuryingPointServiceImpl implements IBuryingPointService {

    @Resource
    private HeroUserVisitRecordStatisticMapper userVisitRecordStatisticMapper;

    @Override
    public void visitRecord(Long fromUid, Long toUid) {
        if (Objects.isNull(fromUid) || Objects.isNull(toUid)) {
            log.error("埋点visitRecord参数错误");
            return;
        }

        AsyncUtil.run(() -> {
            HeroUserVisitRecordStatistic saveRecord = new HeroUserVisitRecordStatistic();
            saveRecord.setFromUid(fromUid);
            saveRecord.setToUid(toUid);
            userVisitRecordStatisticMapper.insert(saveRecord);
        });
    }
}
